package com.matianle.springboot_code1.exception;

import com.matianle.springboot_code1.pojo.dto.ReponseMessage;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.net.http.HttpResponse;

@RestControllerAdvice //统一处理
public class GlobalExceptionHandlerAdvice {

    Logger log= LoggerFactory.getLogger(GlobalExceptionHandlerAdvice.class);
    @ExceptionHandler({Exception.class})  //统一全局处理
    public ReponseMessage handleException(Exception e, HttpServletRequest request, HttpServletResponse response){
        log.error("统一异常",e);
        return new ReponseMessage(500,"error",null);
    }

}
